package com.bole.controller;

import com.bole.data.Result;
import com.bole.data.ResultEnum;
import com.bole.dto.brand.DicBrandDto;
import com.bole.dto.brand.TbCarSeriesDto;
import com.bole.feign.DicBrandFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("brand")
@Api(value = "品牌管理接口")
public class BrandController {
    @Autowired
    private DicBrandFeign brandFeign;


    @RequestMapping("toList")
    public String carSeriesList(){

        return "brand-list";
    }

    @GetMapping("getBrandInfo")
    @ApiOperation(value = "查询品牌信息",notes = "查询品牌信息")
    @ResponseBody
    public Result getSeriesInfo(){
        List<DicBrandDto> brandDtos = brandFeign.getBrandInfo();
        return Result.response(ResultEnum.OK).setData(brandDtos);
    }


    @PostMapping("saveBrandInfo")
    @ApiOperation(value = "增加品牌信息",notes = "增加品牌信息")
    @ApiImplicitParam(name = "brandDto",value = "品牌对象",required = true,dataTypeClass = DicBrandDto.class)
    @ResponseBody
    public Result saveBrandInfo(@RequestBody DicBrandDto brandDto){
        brandFeign.saveBrandInfo(brandDto);
        return Result.response(ResultEnum.OK);
    }


    @PostMapping("toUpdate/{id}")
    @ApiOperation(value = "回显",notes = "没啥好注释的")
    @ApiImplicitParam(name = "id",value = "广告id",required = true,dataTypeClass = Long.class)
    @ResponseBody
    public Result toUpdate(@PathVariable("id")Long id){
        DicBrandDto brandDto = brandFeign.toUpdate(id);
        return Result.response(ResultEnum.OK).setData(brandDto);
    }


    @PostMapping("updateBrandInfo")
    @ApiOperation(value = "修改信息",notes = "修改信息")
    @ApiImplicitParam(name = "brandDto",value = "品牌对象",required = true,dataTypeClass = DicBrandDto.class)
    @ResponseBody
    public Result updateBrandInfo(@RequestBody DicBrandDto brandDto){
        brandFeign.updateBrandInfo(brandDto);
        return Result.response(ResultEnum.OK);
    }


    @PostMapping("deleteBatch/{ids}")
    @ApiOperation(value = "批量删除信息",notes = "批量删除信息")
    @ApiImplicitParam(name = "ids",value = "广告id集",required = true,paramType = "path",dataTypeClass = Long.class)
    @ResponseBody
    public Result deleteBatch(@PathVariable("ids")Long[] ids){
        List<Long> idss = new ArrayList<>();
        for (Long id : ids) {
            idss.add(id);
        }
        brandFeign.deleteBatch(idss);
        return Result.response(ResultEnum.OK);
    }
}
